<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="servlets.*"%>
<%@ page import="org.hibernate.SessionFactory"%>
<%@ page import="org.hibernate.Session"%>
<%@ page import="java.util.List"%>
<%@ page import="hibernate.model.*"%>
<%@ page import="hibernate.util.HibernateUtil"%>
<%@ page import="hibernate.method.*"%>

<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<div class="page-header">
	<h2 class="page-title">statystyki</h2>
</div>
<div id="content">
<br />
<%
						SessionFactory sessionFactory = HibernateUtil
								.getSessionAnnotationFactory();
						Session s = sessionFactory.openSession();
						s.beginTransaction();
							response.setContentType("text/html");
							UserMethods um= new UserMethods();
							EventMethods em = new EventMethods();
							LocalMethods lm = new LocalMethods();
							RateMethods rm = new RateMethods();
%>

<table>
<tr>
<td>Ilość zarejestrowanych uzytkownikow:</td>
<td><%out.print(um.countClients(sessionFactory, s));%>			</td>
<td> W tym: 							</td>
</tr>

<tr>
<td>Ilość dokonanych rezerwacji: </td>
<td>		<%=em.countAllReservations(sessionFactory, s) %>						</td>
<td>

<div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>
</td>
<%

out.println("<script type=\"text/javascript\">");
out.println("$(function () {");
out.println("$('#container').highcharts({");
out.println("chart: {");
out.println("plotBackgroundColor: null,");
out.println("plotBorderWidth: null,");
out.println("plotShadow: false");
out.println("},");
out.println("title: {");
out.println("text: ");
out.println("'Ilosc dokonanych rezerwacji w poszczegolnych lokalach'");
out.println("},");
out.println("tooltip: {");
out.println("pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'");
out.println("},");
out.println("plotOptions: {");
out.println("pie: {");
out.println("allowPointSelect: true,");
out.println("cursor: 'pointer',");
out.println("dataLabels: {");
out.println("enabled: true,");

out.println("		                    format: '<b>{point.name}</b>: {point.percentage:.1f} %',");
out.println("		                    style: {");
out.println("		                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'");
out.println("	                    }");
		out.println("                }");
		    out.println("        }");
out.println("		        },");
out.println("		        series: [{");
	out.println("	            type: 'pie',");
		out.println("name: 'Liczba rezerwacji w lokalach',");
		out.println("data : [");
		
		 List <Local> locals = lm.listAllLocals(sessionFactory, s);
		for (Local l: locals ){
			out.print("['");
			out.print(l.getCity()+", "+l.getStreet()+" "+l.getLocal_number());
			out.print("', ");
			out.print(em.countReservationsByLocal(sessionFactory, s, l.getLocal_id()));
			out.print("],");
		}
		out.println("['Inne', 0.0]");
		out.println("]");
		out.println("}]");
		out.println("});");
		out.println("});");
		out.println("</script>");
%>
<td> </td>
<br>
<br>
<tr>
<td>
Srednia ocena wszystkich lokali </td>
<td><% %></td>
<td>  (Dla kazdego lokalu) </td>
<td><%for (Local l: locals ){
	out.print(l.getCity()+", "+l.getStreet()+" "+l.getLocal_number());
	out.print(": ");
	out.println(rm.returnAverageRateByLocal(sessionFactory, s, l.getLocal_id()));%>
	<BR>
	<%} %>
	</td>
</tr>

Najwięcej rezerwacji dokonano w dniu / lokalu
Najpopularniejszy użytkownik [ ma najwięcej przyjaciol]
Najchętniej komentowana gra/ lokal
Najpopularniejszy lokal
Największy komentator:



</table>


	<%
		
		s.getTransaction().commit();
		%>

</div>		
		